package com.sugon.springboot.controller;

import com.sugon.springboot.entities.CommonResult;
import com.sugon.springboot.entities.Payment;
import com.sugon.springboot.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        if (paymentService.create(payment)>0){
            return new CommonResult(200,"success",payment);
        }
        else {
            return new CommonResult(404,"false",null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult select(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        if (payment!=null){
            return new CommonResult(200,"success",payment);
        }
        else {
            return new CommonResult(404,"没有对应记录："+id,null);
        }
    }
    @Value("${server.port}")
    private String serverPort;
    @GetMapping("/payment/lb")
    public String returnId(){
        return serverPort;
    }
}
